let {
  addlink
} = require("../../../api/attract/select");
var t = new(require("../../../utils/http").HTTP)();
let citys=require("../../../utils/citys2")

Page({
  data: {
    fieldNames: {
      text: 'label',
      value: 'label',
      children: 'children',
    },
    show: false,
    options:citys.citys,
    fieldValue: '',
    cascaderValue: '',
    region: ["", "", ""],

    lxrxlList: [{
        text: "暂无",
        id: "暂无"
      },
      {
        text: "高中及以下",
        id: "高中及以下"
      },
      {
        text: "大专",
        id: "大专"
      },
      {
        text: "本科",
        id: "本科"
      },
      {
        text: "硕士",
        id: "硕士"
      },
      {
        text: "博士",
        id: "博士"
      },
    ],
    lxrxl: "暂无",
    zhuti: [{
        id: 1,
        text: "法人",
      },
      {
        id: 2,
        text: "主办会计",
      },
      {
        id: 3,
        text: "主要负责人",
      },
      {
        id: 4,
        text: "日常联系人",
      },
      {
        id: 5,
        text: "租住使用人",
      },
    ],
    title: "请选择",
  },
  onClick() {
    this.setData({
      show: true,
    });
  },

  onClose() {
    this.setData({
      show: false,
    });
  },

  onFinish(e) {
    console.log(e.detail)
    const { selectedOptions, value } = e.detail;
    const fieldValue = `${selectedOptions[0].label}/${selectedOptions[1].label}`;
    this.setData({
      fieldValue,
      cascaderValue: value,
      'region[0]':selectedOptions[0].label,
      'region[1]':selectedOptions[1].label,
      // 'region[2]':selectedOptions[2].label,
    })
    console.log(this.data.region)
    this.onClose()
  },
  bindRegionChange: function (e) {
    console.log("picker发送选择改变，携带值为", e.detail.value);
    this.setData({
      region: e.detail.value,
    });
  },
  lxrxlEvent: function (t) {
    this.setData({
      lxrxl: t.detail.selectedID,
      lxrxl: t.detail.nowText,
    });
  },
  selectEvent: function (t) {
    this.setData({
      type: t.detail.selectedID,
      title: t.detail.nowText,
    });
  },
  quxiao: function () {
    wx.navigateBack({
      delta: 1,
    });
  },
  formSubmit: function (e) {
    var n = e.detail.value,
      a = this;
    wx.showModal({
      title: "提示",
      content: "请核对数据是否确定修改",
      success: function (e) {
        e.confirm &&
          ("" == n.name || "" == n.iphone || null == a.data.title ||''==a.data.region[0]?
            wx.showToast({
              title: "请检查是否有必填项未填",
              icon: "none",
              duration: 1e3,
            }) :
            addlink({
              qymc: a.data.qymc,
              lxr: n.name,
              iphone: n.iphone,
              tname: a.data.tname[0],
              khbh: a.data.infor.khbh,
              lxrxl: a.data.lxrxl,
              lxrjga: a.data.region[0],
              lxrjgb: a.data.region[1],
              // lxrjgc: a.data.region[2],
              lxryx: n.lxryx,
              grah: n.grah,
            }).then(function (e) {
              t.request({
                url: "https://www.qlsyyun.com:3000/addlink/stjd",
                header: {
                  "Content-Type": "application/x-www-form-urlencoded",
                },
                method: "POST",
                data: {
                  qymc: a.data.qymc,
                  xm: n.name,
                  iphone: n.iphone,
                  zsy: a.data.tname[0],
                  khbh: a.data.infor.khbh,
                  bm: a.data.tname[1],
                },
              }).then(function (t) {
                wx.showToast({
                  title: "提交成功",
                  icon: "none",
                  duration: 1e3,
                  mask: !0,
                  success: function () {
                    setTimeout(function () {
                      let pages = getCurrentPages()
                      let beforePage = pages[pages.length - 2];
                      // 假设main()为页面A的数据方法，
                      beforePage.onLoad({
                        bID: a.data.infor.bID,
                        id: 1,
                qdid:a.data.infor.bID

                      });
                      wx.navigateBack({
                        delta: 1,
                      });
                    }, 1e3);
                  },
                });
              });
            }));
      },
    });
  },
  onLoad: function (t) {
    var e = wx.getStorageSync("user"),
      n = wx.getStorageSync("infor");
    this.setData({
      qymc: t.qymc,
      infor: n,
      tname: e,
    });
  },
});